#ifndef GENOMEELEMENT_H
#define GENOMEELEMENT_H

#include <QObject>
#include <QDebug>
#include <QPointer>

#include "../../sagevis.h"
#include "../../VisBaseClasses/visbaseelement.h"
#include "BaseDataManagement/genomeelementdatapacket.h"
#include "../../VisBaseClasses/visbasewidget.h"
#include "multigeneregionviswidget.h"

#define     ALIGNMENT_CONNECTION    8
#define     CENTER_CONNECTION       9

class SageVis;
class VisBaseElement;
class GenomeElementDataPacket;
class VisBaseWidget;
class Contig;

class GenomeElement : public VisBaseElement
{
    Q_OBJECT
public:
    explicit GenomeElement(QPointer<SageVis> sageVisPointer, MultiGeneRegionVisWidget* parentWidget, Contig* parent);
    explicit GenomeElement(QPointer<GenomeElementDataPacket> dataPacket, QPointer<SageVis> sageVisPointer, MultiGeneRegionVisWidget* parentWidget, Contig* parent);

    typedef VisBaseElement super;
    friend class InfoBox;

    void setDataPacket( QPointer<GenomeElementDataPacket> dataPacket );

    int getStart();
    int getStop();
    QString getClusterId();
    QPointer< Contig > getParentContig();
    QString getUniqueId();
    void setDrawForward(bool);
    bool getDrawForward();

    QColor getColor();
    void setColor(QColor newColor);
    void setColor(QColor newColor, bool emitSignal);
    void setHighlightColor();

    //PAINT FUNCTIONS
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
               QWidget *widget);

    void forgeConnection(QPointer<VisBaseElement> elt, int type);

    void setGeometry(const QRectF &geom);
    void setGeometry( qreal x, qreal y, qreal w, qreal h );
    void setWidth(float w);
    void setHeight(float h);

    void setIdx(int idx);
    int getIdx();

    QString getIdentifierToDisplay();

    void processHoverEvent(QGraphicsSceneHoverEvent *event);
    void processColorChangeEvent(QColor newColor);

signals:
    void showInfoBoxSignal( GenomeElementDataPacket*, GenomeElement* );
    void removeInfoBoxSignal( GenomeElementDataPacket*, GenomeElement* );
    void alignmentSignal(float xPos, bool posStrand, QString parentContigId);//pos is in widget coordiantes
    void centerSignal();
    void moveToTopSignal(QString clusterId);
    void targetSignal(QString clusterId);

    void signalingHover(bool hover, QGraphicsSceneHoverEvent* event, QString key);
    void signalingColorChange(QColor c, QString key );
    void signalingAlignment( float xPos, bool posStrand, QString parentContigId, QString key);
    void signalingCenter(QString key);

public slots:
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
    void emitAlignmentSlot();
    void emitCenteredSlot();
    void emitMoveToTopSlot();
    void emitTargetSlot();
    void emitTargetSlot(QColor leftColor, QColor rightColor, QColor startColor);
    void alignmentSlot(float xPos, bool posStrand, QString parentContigId);//pos is in widget coordinates
    void centerSlot();
    //void colorChangedSlot(QColor);

private:
    QPointer< GenomeElementDataPacket > dataPacket;
    QPointer< Contig > parentContig;

    void init();
    void initShape();

    QColor defaultColor;
    QColor givenColor;
    QColor highlightColor;
    QColor backgroundColor;

    QRectF bRect;
    QPointF p1;
    QPointF p2;
    QPointF p3;
    QPolygonF poly;

    bool drawArrow;
    bool drawForward;

    QPointer<InfoBox> infoBox;

    QString uniqueId;

    //I don't think these are needed...
    bool emitAlignmentSignal;
    bool acceptAlignmentSignals;

    bool emitCenterSignal;
    bool acceptCenterSignals;

    int idx;
};

#endif // GENOMEELEMENT_H
